﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Chinaer.WCF.Services;

namespace Chinaer.UI.MVC.Controllers
{
    public class CountryController : Controller
    {
        //
        // GET: /Country/

        public ActionResult Index()
        {

            return View();
        }
        /// <summary>
        /// 获取所有的国家列表
        /// </summary>
        /// <returns></returns>
        public ContentResult GetCountries()
        {
            ChinaerService chinaerService = new ChinaerService();
            List<DTO.CountryDTO> listCountry = chinaerService.GetAllCountry("");
            string jsonResult = Helper.JsonHelper.GetJson(listCountry, listCountry.Count);
            //return new JsonResult()
            //{
            //    Data = jsonResult,
            //    JsonRequestBehavior = JsonRequestBehavior.AllowGet
            //};
            return new ContentResult()
            {
                Content = jsonResult
            };
        }
        public ContentResult GetAllCountries()
        {
            ChinaerService chinaerService = new ChinaerService();
            List<DTO.CountryDTO> listCountry = chinaerService.GetAllCountry("");
            string jsonResult = Helper.JsonHelper.CreateJson(listCountry);
            //return new JsonResult()
            //{
            //    Data = jsonResult,
            //    JsonRequestBehavior = JsonRequestBehavior.AllowGet
            //};
            return new ContentResult()
            {
                Content = jsonResult
            };
        }

        [HttpPost]
        public string SaveCountry(DTO.CountryDTO countryDTO)
        {
            ChinaerService chinaService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaService.AddCountry(countryDTO);
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
        [HttpPost]
        public string UpdateCountry(DTO.CountryDTO countryDTO)
        {
            ChinaerService chinaService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaService.UpdateCountry(countryDTO);
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
        [HttpPost]
        public string DeleteCountry(string ID)
        {
            ChinaerService chinaService = new ChinaerService();
            Model.Common.JsonResult jsonResult = chinaService.DeleteCountryByID(ID, "");
            return Helper.JsonHelper.CreateJson(jsonResult);
        }
    }
}
